<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>View Delivery Order| Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <h:form>    
            <p:dataTable var="deliveryOrder" value="#{viewDeliveryOrderManagerBean.deliveryOrder}" 
                         dynamic="true" paginator="true" rows="5" emptyMessage="No Delivery Order Record" selection="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder}" onRowSelectUpdate="display">
                <p:column selectionMode="single"/>
                
                <p:column sortBy="#{deliveryOrder.id}" filterBy="#{deliveryOrder.id}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Delivery Order ID" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.id}" /> 
                </p:column> 

                <p:column sortBy="#{deliveryOrder.saleOrder.id}" filterBy="#{deliveryOrder.saleOrder.id}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Sale Order ID" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.saleOrder.id}" /> 
                </p:column> 

                <p:column sortBy="#{deliveryOrder.pickingOrder.pickingState}" filterBy="#{deliveryOrder.pickingOrder.pickingState}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Picking Order State" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.pickingOrder.pickingState}" /> 
                </p:column>

              
                
                <p:column sortBy="#{deliveryOrder.packingOrder.packingState}" filterBy="#{deliveryOrder.packingOrder.packingState}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Packing Order State" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.packingOrder.packingState}" /> 
                </p:column>
                
                
                <p:column sortBy="#{deliveryOrder.shippingOrder.shippingState}" filterBy="#{deliveryOrder.shippingOrder.shippingState}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Shipping Order State" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.shippingOrder.shippingState}" /> 
                </p:column>
                
                <p:column sortBy="#{deliveryOrder.deliveryState}" filterBy="#{deliveryOrder.deliveryState}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Delivery State" /> 
                    </f:facet> 
                    <h:outputText value="#{deliveryOrder.deliveryState}" /> 
                </p:column>

                <f:facet name="footer">  
                    <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="saleOrderViewDialog.show()"/>
                    <p:commandButton value="Delete" actionListener="#{viewDeliveryOrderManagerBean.deleteDeliveryOrder}"/>
                    <p:commandButton value="Create Picking Order" actionListener="#{viewDeliveryOrderManagerBean.createPickingOrder}"/>
                    <p:commandButton value="Create Packing Order" actionListener="#{viewDeliveryOrderManagerBean.createPackingOrder}"/>
                    <p:commandButton value="Create Shipping Order" actionListener="#{viewDeliveryOrderManagerBean.createShippingOrder}"/>
                    <p:commandButton value ="Trigger delivery success" actionListener="#{viewDeliveryOrderManagerBean.test}"/> 
                </f:facet>

            </p:dataTable>
            
            <p:dialog header="Sale Order Detail" widgetVar="saleOrderViewDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                <h:panelGrid id="display1" columns="2" cellpadding="4">
                    
                    <h:outputText value="SaleOrder ID:"/>
                    <h:outputText value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.id}"/>
                    
                    <h:outputText value="Date:"/>
                    <h:outputText value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.saleOrderDate}"/>
                    
                    <h:outputText value="Customer ID:"/>
                    <h:outputText value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.customer.registrationNumber}"/>
                    
                    <h:outputText value="Customer Name:"/>
                    <h:outputText value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.customer.saleLeadName}"/>
                
                </h:panelGrid>
                
                <p:dataTable var="lineItem" value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.lineItems}"
                             dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                    <p:column sortBy="#{lineItem.productPrice.productType}">
                        <f:facet name="header">
                            <h:outputText value="Product Type"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.productPrice.productType}"/>
                    </p:column>
                        
                    <p:column sortBy="#{lineItem.lineItemQuantity}">
                        <f:facet name="header">
                            <h:outputText value="Quantity"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.lineItemQuantity}"/>
                    </p:column>
                    
                    <p:column sortBy="#{lineItem.productPrice.productPrice}">
                        <f:facet name="header">
                            <h:outputText value="Price"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.productPrice.productPrice}"/>
                    </p:column>
                    <f:facet name="footer">
                        <h:outputText value="Total Price: "/>
                        <h:outputText value="#{viewDeliveryOrderManagerBean.selectedDeliveryOrder.saleOrder.totalPrice}"/>                        
                    </f:facet>
                 </p:dataTable>
   
            </p:dialog>

        </h:form>
    </ui:define>

</ui:composition>